package com.example.pharmacypick.controller;


import com.example.pharmacypick.dto.RecordDto;
import com.example.pharmacypick.pojo.Record;
import com.example.pharmacypick.service.RecordService;
import com.example.pharmacypick.utils.RespBean;
import com.example.pharmacypick.vo.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/record")
public class RecordController {

    @Autowired
    RecordService recordService;

    @GetMapping
    public RespBean findAllRecords(@RequestParam Integer pageNum,@RequestParam Integer pageSize,@RequestParam String patientName){
        try {
            RecordDto recordDto=new RecordDto();
            recordDto.setPatientName(patientName);
            recordDto.setPageNum(pageNum);
            recordDto.setPageSize(pageSize);
            PageInfo<Record> allRecords = recordService.findALlRecords(recordDto);
            return RespBean.success("成功",allRecords);
        }catch (Exception e){
            e.printStackTrace();
            return RespBean.error("error");
        }
    }

    //插入查询记录
    @GetMapping("/addRecord")
    public RespBean addRecordByPrescriptionId(@RequestParam int prescriptionId){
        try {
            recordService.addRecordByPrescription(prescriptionId);
            return RespBean.success("成功");
        }catch (Exception e){
            e.printStackTrace();
            return RespBean.error("error");
        }
    }
}
